<?php
function is_date ($str, $retype = 0)
{
    $reVal = "";
    $dateArr = explode("-", $str);
    if (count($dateArr) != 3)
    {
        return false;
    }
    $year = $dateArr[0];
    $month = $dateArr[1];
    $day = $dateArr[2];
    switch ($retype)
    {
        case 1 :
            if (checkdate($month, $day, $year))
            {
                $reVal = sprintf("%04d-%02d-%02d", $year, $month, $day);
            }
            else
            {
                $reVal = false;
            }
            break;
        default :
            $reVal = checkdate($month, $day, $year);
            break;
    }
    return $reVal;
}

function getProtmode_3d ($user_id, $gametype)
{
    $fieldName = "protmod";
    $userTemp = get_user($user_id, $gametype);
    $acl = $userTemp['acl'];
    switch ($acl)
    {
        case 1 :
            $sql = "SELECT f.{$fieldName} FROM k_user a ";
            $sql .= " LEFT JOIN k_user b ON a.id = b.prev_id";
            $sql .= " LEFT JOIN k_user c ON b.id = c.prev_id";
            $sql .= " LEFT JOIN k_user d ON c.id = d.prev_id";
            $sql .= " LEFT JOIN k_user e ON d.id = e.prev_id";
            $sql .= " LEFT JOIN k_user_percent f ON a.id = f.user_id";
            $sql .= " WHERE e.id={$user_id} AND a.acl = 5 AND f.gametype = {$gametype}";
            break;
        case 2 :
            $sql = "SELECT f.{$fieldName} FROM k_user a";
            $sql .= " LEFT JOIN k_user b ON a.id = b.prev_id";
            $sql .= " LEFT JOIN k_user c ON b.id = c.prev_id";
            $sql .= " LEFT JOIN k_user d ON c.id = d.prev_id";
            $sql .= " LEFT JOIN k_user_percent f ON a.id = f.user_id";
            $sql .= " WHERE d.id={$user_id} AND a.acl = 5 AND f.gametype = {$gametype}";
            break;
        case 3 :
            $sql = "SELECT f.{$fieldName} FROM k_user a";
            $sql .= " LEFT JOIN k_user b ON a.id = b.prev_id";
            $sql .= " LEFT JOIN k_user c ON b.id = c.prev_id";
            $sql .= " LEFT JOIN k_user_percent f ON a.id = f.user_id";
            $sql .= " WHERE c.id={$user_id} AND a.acl = 5 AND f.gametype = {$gametype}";
            break;
        case 4 :
            $sql = "SELECT f.{$fieldName} FROM k_user a";
            $sql .= " LEFT JOIN k_user b ON a.id = b.prev_id";
            $sql .= " LEFT JOIN k_user_percent f ON a.id = f.user_id";
            $sql .= " WHERE b.id={$user_id} AND a.acl = 5 AND f.gametype = {$gametype}";
            break;
        case 5 :
            $sql = "SELECT f.{$fieldName} FROM k_user a";
            $sql .= " LEFT JOIN k_user_percent f ON a.id = f.user_id";
            $sql .= " WHERE a.id={$user_id} AND a.acl = 5 AND f.gametype = {$gametype}";
            break;
        default :
            return 1;
    }
    $rs = getdb($sql);
    if (!$rs->eof)
    {
        return $rs->f[0];
    }
    return false;
}

?>